package com.ndx.service.impl;

import com.ndx.mapper.CategoryMapper;
import com.ndx.pojo.Category;
import com.ndx.service.CategoryService;
import com.ndx.utils.ThreadLocalUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class CategoryServiceImpl implements CategoryService {
    @Autowired
    private CategoryMapper categoryMapper;
    @Override
    public void add(Category category) {
       Map<String,Object> map =  ThreadLocalUtil.get();
       Integer id =(Integer) map.get("id");
       category.setCreateUser(id);
        categoryMapper.add(category);
    }

    @Override
    public List<Category> list() {
        Map<String,Object> map =  ThreadLocalUtil.get();
        Integer id =(Integer) map.get("id");
        System.out.println(id);
        System.out.println(categoryMapper.list(id));
        return categoryMapper.list(id);
    }

    @Override
    public Category findById(Integer id) {
        Category c =categoryMapper.findById(id);
        return c;
    }

    @Override
    public void update(Category category) {
        categoryMapper.update(category);
    }

    @Override
    public void delete(Integer id) {
        categoryMapper.delete(id);
    }
}
